package gui;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.*;

import javax.swing.*;


public class PanelMeny extends JPanel implements ActionListener{
	private JButton buttonNyRett, buttonEndre, buttonFjernRett, buttonTilbake, buttonHovedmeny;
	private GridBagConstraints constraints;
	private JLabel labelAdministrereMeny;
	public PanelMeny(){
		this.setLayout(new GridBagLayout());
		this.leggTilKnapper();
		GUI.getVindu().add(this);
	}
	private void leggTilKnapper(){
		buttonNyRett = new JButton("Legg til ny rett");
		buttonNyRett.addActionListener(this);
		
		buttonHovedmeny= new JButton("Tilbake til hovedmeny");
		buttonHovedmeny.addActionListener(this);
		
		buttonEndre = new JButton("Endre rett");
		buttonEndre.addActionListener(this);
		
		buttonFjernRett = new JButton("Fjern rett");
		buttonFjernRett.addActionListener(this);
		
		buttonTilbake = new JButton("Tilbake");
		buttonTilbake.addActionListener(this);
		
		labelAdministrereMeny = new JLabel("Administrer meny");
		Font f = new Font(labelAdministrereMeny.getFont().getName(), labelAdministrereMeny.getFont().getStyle(), 30);
		labelAdministrereMeny.setFont(f);
		
		constraints = new GridBagConstraints();
		constraints.gridwidth = 3;
		this.add(labelAdministrereMeny, constraints);
		constraints.gridwidth = 1;
		constraints.ipadx = 60;
		constraints.ipady = 30;
		constraints.insets = new Insets(10, 10, 10, 10);
		constraints.gridy = 1;
		constraints.gridx = 0;
		constraints.anchor = GridBagConstraints.LINE_END;
		this.add(buttonNyRett,constraints);
		constraints.gridx = 1;
		constraints.anchor = GridBagConstraints.CENTER;
		this.add(buttonEndre, constraints);
		constraints.gridx = 2;
		constraints.anchor = GridBagConstraints.LINE_START;
		this.add(buttonFjernRett,constraints);
		constraints.ipadx = 30;
		constraints.ipady = 15;
		constraints.gridy = 2;
		constraints.gridx = 1;
		constraints.anchor = GridBagConstraints.LINE_END;
		this.add(buttonTilbake, constraints);
		constraints.anchor = GridBagConstraints.LINE_START;
		constraints.gridx = 2;
		this.add(buttonHovedmeny, constraints);
	}
	private void buttonNyRett_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
		new PanelNyRett();		
	}

	private void buttonFjernRett_actionPerformed(ActionEvent e)
	{
		this.setVisible(false);
		new PanelFjernRett();
	}
	private void buttonHovedmeny_actionPerformed(ActionEvent e) {
		this.setVisible(false);
		new PanelHovedmeny();
		
	}
	private void buttonEndre_actionPerformed(ActionEvent e) {
		this.setVisible(false);
		new PanelEndreRett();
		
	}
	private void buttonTilbake_actionPerformed(ActionEvent e) {
		this.setVisible(false);
		new PanelAdmin();
		
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource()==buttonNyRett)
			buttonNyRett_actionPerformed(e);
		else if(e.getSource()==buttonFjernRett)
			buttonFjernRett_actionPerformed(e);
		else if(e.getSource()==buttonHovedmeny){
			buttonHovedmeny_actionPerformed(e);
		}
		else if(e.getSource()==buttonEndre){
			buttonEndre_actionPerformed(e);
		}
		else if(e.getSource()== buttonTilbake)
			buttonTilbake_actionPerformed(e);
		
	}
	
}
